package com.hualan.sfzy.service.content.serviceimpl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.content.Article;
import com.hualan.sfzy.mapper.content.ArticleMapper;
import com.hualan.sfzy.service.content.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("articleService")
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper mapper;

    public  int add(Article article){
        return mapper.insert(article);
    }
    public int remove(Integer id){
        return mapper.delete(id);
    }
    public int removeBatch(Integer[] ids){
        return mapper.deleteBatch(ids);
    }
    public int edit(Article article){
        return mapper.update(article);
    }
    public Article findById(Integer id){
        return mapper.selectById(id);
    }
    public List<Article> find(){
        return mapper.select(null);
    }

    public Map<String,Object> findPage(Integer pageNum, Integer pageSize, Article article){
        System.out.println(pageNum+" "+pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<Article> list = mapper.select(article);
        PageInfo<Article> pageInfo = new PageInfo<>(list);
        Map<String , Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;

    }
}



